<html>
<head><meta charset="utf-8"><title>Find reachable function calls? · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20reachable.20function.20calls.3F.html">Find reachable function calls?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="207441669"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20reachable%20function%20calls%3F/near/207441669" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20reachable.20function.20calls.3F.html#207441669">(Aug 19 2020 at 18:05)</a>:</h4>
<p>Is there a way to, given a function body, see all the functions that it calls? Having the original HIR/expression span would be ideal but I can live with just the name of the caller and callee function.</p>
<p>Presumably this is somewhere in <code>rustc_codegen_ssa</code>, but I'm not sure where to look.</p>



<a name="207442017"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20reachable%20function%20calls%3F/near/207442017" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20reachable.20function.20calls.3F.html#207442017">(Aug 19 2020 at 18:08)</a>:</h4>
<p>note that this is not _in general_ possible, e.g., virtual dispatch would break it</p>



<a name="207442030"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20reachable%20function%20calls%3F/near/207442030" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20reachable.20function.20calls.3F.html#207442030">(Aug 19 2020 at 18:08)</a>:</h4>
<p>so maybe say more about the use case?</p>



<a name="207442054"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20reachable%20function%20calls%3F/near/207442054" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20reachable.20function.20calls.3F.html#207442054">(Aug 19 2020 at 18:09)</a>:</h4>
<p><span class="user-mention" data-user-id="124288">@oli</span>'s inlining cycle detection might be relevant?</p>



<a name="207442293"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20reachable%20function%20calls%3F/near/207442293" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20reachable.20function.20calls.3F.html#207442293">(Aug 19 2020 at 18:11)</a>:</h4>
<p>the use case is partly for a research-ish project but the eventual goal is for rustdoc to be able to show callgraphs</p>



<a name="207442342"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20reachable%20function%20calls%3F/near/207442342" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20reachable.20function.20calls.3F.html#207442342">(Aug 19 2020 at 18:12)</a>:</h4>
<p>so you see <code>fn f()</code> in the docs, but you can also search for callers and callees</p>



<a name="207442351"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20reachable%20function%20calls%3F/near/207442351" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20reachable.20function.20calls.3F.html#207442351">(Aug 19 2020 at 18:12)</a>:</h4>
<p>and maybe have a graph view of what your control flow looks like</p>



<a name="207442397"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20reachable%20function%20calls%3F/near/207442397" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20reachable.20function.20calls.3F.html#207442397">(Aug 19 2020 at 18:12)</a>:</h4>
<blockquote>
<p>virtual dispatch</p>
</blockquote>
<p>gotcha, having a call to <code>&lt;dyn T&gt;::func_name</code> would be good enough though I think</p>



<a name="207442413"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20reachable%20function%20calls%3F/near/207442413" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20reachable.20function.20calls.3F.html#207442413">(Aug 19 2020 at 18:13)</a>:</h4>
<p>that sounds like a bit of a overextension of rustdoc to me but okay :)</p>



<a name="207442428"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20reachable%20function%20calls%3F/near/207442428" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20reachable.20function.20calls.3F.html#207442428">(Aug 19 2020 at 18:13)</a>:</h4>
<p>yeah I might put it in a separate tool</p>



<a name="207442491"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20reachable%20function%20calls%3F/near/207442491" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20reachable.20function.20calls.3F.html#207442491">(Aug 19 2020 at 18:13)</a>:</h4>
<p>but I think it would be really cool :)</p>



<a name="207442760"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20reachable%20function%20calls%3F/near/207442760" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20reachable.20function.20calls.3F.html#207442760">(Aug 19 2020 at 18:16)</a>:</h4>
<p>rust-analyzer does something like this I think</p>



<a name="207442778"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20reachable%20function%20calls%3F/near/207442778" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20reachable.20function.20calls.3F.html#207442778">(Aug 19 2020 at 18:16)</a>:</h4>
<p>there's some sort of "get references" invocation</p>



<a name="207442788"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20reachable%20function%20calls%3F/near/207442788" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20reachable.20function.20calls.3F.html#207442788">(Aug 19 2020 at 18:16)</a>:</h4>
<p>not sure how that's powered</p>



<a name="207442937"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20reachable%20function%20calls%3F/near/207442937" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20reachable.20function.20calls.3F.html#207442937">(Aug 19 2020 at 18:17)</a>:</h4>
<p>ok neat, let me go look :)</p>



<a name="207443129"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20reachable%20function%20calls%3F/near/207443129" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20reachable.20function.20calls.3F.html#207443129">(Aug 19 2020 at 18:19)</a>:</h4>
<p>hmm I don't see a <code>get_references</code> function ... <span class="user-mention" data-user-id="133169">@matklad</span> does this sound familiar to you?</p>



<a name="207443290"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20reachable%20function%20calls%3F/near/207443290" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20reachable.20function.20calls.3F.html#207443290">(Aug 19 2020 at 18:20)</a>:</h4>
<p><a href="https://github.com/rust-analyzer/rust-analyzer/blob/9051d6bc366804fde7c69074950363fc2956a2e1/crates/ide/src/call_hierarchy.rs">https://github.com/rust-analyzer/rust-analyzer/blob/9051d6bc366804fde7c69074950363fc2956a2e1/crates/ide/src/call_hierarchy.rs</a></p>



<a name="207443662"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20reachable%20function%20calls%3F/near/207443662" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20reachable.20function.20calls.3F.html#207443662">(Aug 19 2020 at 18:24)</a>:</h4>
<p><code>fn call_hierarchy</code> looks like exactly what I'm imagining <span aria-label="heart" class="emoji emoji-2764" role="img" title="heart">:heart:</span> rust-analyzer works on positions and not IDs but otherwise this is perfect :)</p>



<a name="207448225"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20reachable%20function%20calls%3F/near/207448225" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20reachable.20function.20calls.3F.html#207448225">(Aug 19 2020 at 19:02)</a>:</h4>
<p>related follow-up question: is there a guide somewhere for using rustc as a library? preferably I'd be able to use the nightly release without compiling from source, but I'm willing to compile if I have to. I just don't know how to do this without <code>x.py</code> on hand.</p>



<a name="207448265"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20reachable%20function%20calls%3F/near/207448265" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20reachable.20function.20calls.3F.html#207448265">(Aug 19 2020 at 19:02)</a>:</h4>
<blockquote>
<p>preferably I'd be able to use the nightly release without compiling from source</p>
</blockquote>
<p>(I think I heard something about custom drivers or plugins?)</p>



<a name="207448285"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20reachable%20function%20calls%3F/near/207448285" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20reachable.20function.20calls.3F.html#207448285">(Aug 19 2020 at 19:02)</a>:</h4>
<p>If you install the <code>rustc-dev</code> component you can directly link to the compiler crates</p>



<a name="207448298"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20reachable%20function%20calls%3F/near/207448298" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20reachable.20function.20calls.3F.html#207448298">(Aug 19 2020 at 19:03)</a>:</h4>
<p>perfect, thanks :)</p>



<a name="207448339"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20reachable%20function%20calls%3F/near/207448339" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20reachable.20function.20calls.3F.html#207448339">(Aug 19 2020 at 19:03)</a>:</h4>
<p>with <code>feature(rustc_private)</code>, ok yeah I do remember hearing about this</p>



<a name="207449327"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20reachable%20function%20calls%3F/near/207449327" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20reachable.20function.20calls.3F.html#207449327">(Aug 19 2020 at 19:11)</a>:</h4>
<p><span class="user-mention silent" data-user-id="211727">Jonas Schievink</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/Find.20reachable.20function.20calls.3F/near/207448285">said</a>:</p>
<blockquote>
<p>If you install the <code>rustc-dev</code> component you can directly link to the compiler crates</p>
</blockquote>
<p>You also need <code>llvm-tools-preview</code> for <code>libLLVM-*.so</code>, which <code>librustc_driver-*.so</code> links against.</p>



<a name="207449477"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20reachable%20function%20calls%3F/near/207449477" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20reachable.20function.20calls.3F.html#207449477">(Aug 19 2020 at 19:13)</a>:</h4>
<p>Ah, right</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>